﻿using System;
using System.Collections.Generic;
using GeoAPI.Geometries;
using NetTopologySuite.Noding;

namespace NetTopologySuite.Geometries.Prepared
{
	internal class PreparedPolygonIntersects : PreparedPolygonPredicate
	{
		public static bool Intersects(PreparedPolygon prep, IGeometry geom)
		{
			return new PreparedPolygonIntersects(prep).Intersects(geom);
		}

		public PreparedPolygonIntersects(PreparedPolygon prepPoly) : base(prepPoly)
		{
		}

		public bool Intersects(IGeometry geom)
		{
			if (base.IsAnyTestComponentInTarget(geom))
			{
				return true;
			}
			if (geom.Dimension == Dimension.Point)
			{
				return false;
			}
			IList<ISegmentString> list = SegmentStringUtil.ExtractSegmentStrings(geom);
			return (list.Count > 0 && this.prepPoly.IntersectionFinder.Intersects(list)) || (geom.Dimension == Dimension.Surface && base.IsAnyTargetComponentInAreaTest(geom, this.prepPoly.RepresentativePoints));
		}
	}
}
